The IDL minimum and maximum operators return the smaller or larger of their operands, as described below.
Note: Negated values must be enclosed in parentheses in order for IDL to interpret them correctly.
Note: If one or both of the operands are objects, the operator may be overloaded.
Operator |
Description |
Example |
< |
Minimum operator. Note: See also Using Minimum or Maximum with Complex Numbers and Using Minimum or Maximum with NaN Values. |
Set A equal to 3: A = 5 < 3 Set A equal to -6. Use parentheses to avoid a syntax error. A = 5 < (-6) Set all points in array ARR that are larger than 100 to 100: ARR = ARR < 100 Set X to the smallest of the three operands: X = X0 < X1 < X2 |
> |
Maximum operator. Note: See also Using Minimum or Maximum with Complex Numbers and Using Minimum or Maximum with NaN Values below. |
Use '>' to avoid taking the log of zero or negative numbers: C = ALOG(D > 1E - 6) Plot positive points only. Negative points are plotted as zero: PLOT, ARR > 0 |
For complex numbers, the absolute value is used to determine which value is smaller or larger. If both values have the same magnitude then the first value is returned.
; Set A equal to 1+2i, since ABS(1+2i) is less than ABS(2-4i):
A = COMPLEX(1,2) < COMPLEX(2,-4)
; Set A equal to 1-2i, since ABS(1-2i) equals ABS(-2+i):
A = COMPLEX(1,-2) < COMPLEX(-2,1)
; Set A equal to 2-4i, since ABS(2-4i) is greater than ABS(1+2i)
A = COMPLEX(1,2) > COMPLEX(2,-4)
; Set A equal to 1-2i, since ABS(1-2i) equals ABS(-2+i)
A = COMPLEX(1,-2) > COMPLEX(-2,1)
Typically in IDL, the result of any operation involving the special value NaN is simply NaN. For efficiency, IDL does not check the values of A and B for NaN values before performing the minimum or maximum operation. If A or B contains a NaN value, the result is undefined and can be either NaN or the other non-NaN value, depending on the specific hardware and operating system. If you suspect that one of your operands contains NaN values, you might want to use the FINITE function to ensure that you return NaN values in the result. For example, if A and B are scalars:
A = !VALUES.F_NAN
B = 5
; Result is undefined and can either be 5 or NaN:
PRINT, A > B
; Result must be NaN if either operand is NaN:
PRINT, ( FINITE(A) && FINITE(B) ) ? ( A > B ) : !VALUES.F_NAN
This second method also avoids any floating-point math errors. If A and B are arrays, the following method can be used:
C = REPLICATE( !VALUES.F_NAN, N_ELEMENTS(A) )
good = WHERE( FINITE(A) and FINITE(B), ngood )
IF ( ngood GT 0 ) THEN C[good] = A[good] > B[good]